﻿@model IEnumerable<FollowPeers.Models.PublicationModel>
@using FollowPeers.Models;
@using WebMatrix.Data;
@{
    ViewBag.Title = "My Publication";
    FollowPeers.Models.FollowPeersDBEntities followPeersDB = new FollowPeers.Models.FollowPeersDBEntities();
    string name = Membership.GetUser().UserName;
    ViewBag.UserName = name;
    FollowPeers.Models.UserProfile myprofile = followPeersDB.UserProfiles.First(p => p.UserName == name);
    int publicationnumber = 1;
    int publicationnumber2 = 1;
    var Fields = (from u in followPeersDB.Specializations
                  select u.Field).Distinct();
    string link = "~/";
    List<FollowPeers.Models.PublicationModel> UploadedPub = new List<FollowPeers.Models.PublicationModel>();
    UploadedPub = followPeersDB.PublicationModels.Where(p => p.UserProfile.UserProfileId == myprofile.UserProfileId).ToList();
    List<FollowPeers.Models.Favourite> FavouriteList = new List<FollowPeers.Models.Favourite>();
    FavouriteList = followPeersDB.Favourites.Where(p => p.UserProfile.UserProfileId == myprofile.UserProfileId && p.ItemType == 6).ToList();
    List<FollowPeers.Models.PublicationModel> RecommendedList = new List<FollowPeers.Models.PublicationModel>();
    List<FollowPeers.Models.Bookmark> BookmarkedPublication = followPeersDB.Bookmarks.Where(p => p.bookmarkType == "Publication" && p.userID == myprofile.UserProfileId).ToList();
    PublicationModel temp = new PublicationModel();
    var db = Database.Open("FollowPeersDB");
    List<FollowPeers.Models.PublicationModel> RankedPub = followPeersDB.PublicationModels.OrderByDescending(p => p.Rank).ToList();

    if (BookmarkedPublication.Count() != 0)
    {
        foreach (var id in BookmarkedPublication)
        {
            temp = followPeersDB.PublicationModels.SingleOrDefault(p => p.publicationID == id.itemID);
            RecommendedList.Add(temp);
        }

    }
    
    }

@Html.Partial("_Header")
<div class="container">
    <div class="box">
        <div class="span12 ">
        <div id="myCarousel" class="carousel slide" style="height:270px">
		    <div class="carousel-inner span8" style="height:270px;margin-left:100px; margin-right:100px">
                <div class="active item"style="height:250px; ">
                @foreach (var i in Model)
                {
                    if (publicationnumber <= 3)
                    {
				    <div class="span3" style="height:250px">
		    	        <div class="thumbnail" style="height:250px">
                        @if (i.imagename != "" && i.imagename != null)
                        {
                            <img src="../../Content/Files/@i.UserProfile.UserName/Publications/@i.imagename" style="height:150px; width:170px;" alt=""/>
                        }
                        else
                        {
                            <img src="../../Content/images/Pub1.png" style="height:150px; width:170px;" alt=""/>
                        }
                            <div class="caption" style="text-align:center">
                                <a href="/PublicationModel/Details/@i.publicationID"><b>@i.title</b></a>
                                    <p>By @i.author</p>            
                            </div>
          		        </div>
          		    </div>
                    }
                    publicationnumber++;
                }
                </div>
                <div class="item" style="height:270px">
                @foreach (var j in RankedPub)
                {
                    if (publicationnumber2 <= 3)
                    {
                        
				    <div class="span3" style="height:250px">
		    	        <div class="thumbnail" style="height:250px;">
                         @if (j.imagename != "" && j.imagename != null)
                         {
                             
                            <img src="../../Content/Files/@j.UserProfile.UserName/Publications/@j.imagename" style="height:150px; width:170px;"alt=""/>
                         }
                         else
                         {
                            <img src="../../Content/images/Pub1.png" style="height:150px; width:170px;"alt=""/>
                         }
                            <div class="caption" style="text-align:center">
                                <a href="/PublicationModel/Details/@j.publicationID"><b>@j.title</b></a>
                                    <p>By @j.author</p>
                                    @for (int i = 0; i < j.Rank; i++)
                                    {
                                    <i class="icon-star"></i>
                                    }
                                     @for (int i = 0; i < (5 - j.Rank); i++)
                                     {
                                    <i class="icon-star-empty"></i>
                                     }
                            </div>
          		        </div>
          		    </div>
                    }
                    publicationnumber2++;
                }
                </div>
                </div>
                <a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
                <a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a>   
         </div>
         </div>
     </div>
            
            <div class="span8">
            <br/>    
                <ul class="nav nav-tabs" id="myTab">               
                    <li id="li_tab1" class="active" onclick="tab('tab1')"><a>All</a></li>
                    <li id="li_tab3" onclick="tab('tab3')"><a>Favourites</a></li>
                    <li id="li_tab4" onclick="tab('tab4')"><a>Peer Recommendations</a></li>
                    <li id="li_tab2" onclick="tab('tab2')"><a>Uploaded</a></li>
                </ul>
                <div class="tab-content">
                    <div id="tab3" style="display: none;" class="tab-pane" >
                       @if (FavouriteList.Count() != 0)
                       {
                             <span class="label label-info">Favourite Publications: @FavouriteList.Count()</span>
                                <table class="span7">  
                                    @foreach (var item in FavouriteList)
                                    {
                                        <tr>
                                            <td>
                                                <div style="border-bottom: 1px solid grey; margin: 10px 0px;">
                                                @{ link = link + item.ItemLink;}
                                                    <a href="@Url.Content(link)" id="title"><b>@item.ItemName</b></a>
                                                    @if (@item.ItemType == 6)
                                                    {
                                                        <div id="Author">Type : Publication </div>
                                                    }
                                                </div>
                                                <hr />
                                            </td>
                                        </tr>
                                    }
                                    </table>
                       }
                       else
                       {
                                    <span class="label label-info">No Favourite Publications Found</span>
                       }
                    </div>
                    <div id="tab1" style="display: none;" class="tab-pane active" >
                     @{
                         if (Model.Count() != 0)
                         {
                             <span class="label label-info">Number of publications: @Model.Count()</span>
                  <table class="span7">  
                   
                @foreach (var item in Model)
                {
                    string mouseid1 = "#mouse" + @item.publicationID;
                    string mouseid2 = "mouse" + @item.publicationID;
                
                    <tr><td>
                    
                <div style="border-bottom: 1px solid grey; margin: 10px 0px;">
                <div style="float: left;" id="mouse" class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="@mouseid1" >
                    @if (item.imagename != "" && item.imagename != null)
                    {
                            <img class="mouseover" src="../../Content/Files/@item.UserProfile.UserName/Publications/@item.imagename" alt="" style="margin-left: auto; margin-right: auto;width: 50px;"/>
                    }
                    else
                    {
                            <img src="../../Content/images/Pub1.png" alt="" style="margin-left: auto; margin-right: auto;width: 50px;"/>
                    }
                </div>
                <div style="margin-left: 8px; float: left;">
                    <a href="/PublicationModel/Details/@item.publicationID" id="title"><b>@item.title</b></a> 
                    <div id="Author">Author(s) : @item.author</div>
                    <div id="Year">Year of Publication : @item.year</div>
                    <div id="@mouseid2" class="accordion-body collapse" >
                    @{if (@item.keyword != null)
                      {<div id="keyword">Keyword(s) : @item.keyword</div>}}
                    @{if (@item.journal != null)
                      {<div id="journal">Journal : @item.journal</div>}}
                    @{if (@item.conference != null)
                      {<div id="conference">Conference : @item.conference</div>}}
                    @{if (@item.university != null)
                      {<div id="university">University : @item.university</div>}}
                </div>
                </div>
                <div style="float: right; margin-right: 5px; color: #888; font-size: 15px;">@Html.DisplayFor(modelItem => item.type)
                    | @Html.DisplayFor(modelItem => item.status)  |
                    <div style="float:right; font-size: 15px; margin-left: 5px;">
                        @Html.ActionLink("More>>", "Details", new { id = item.publicationID })
                    </div>
                    </div>
            </div>
            <hr /> 
            </td></tr>
   
                }
                </table>
                         }
                         else
                         {
                <span class="label label-info">Number of publications uploaded: @Model.Count()</span>
                         }
      }  
                    </div>
                    <div id="tab4" style="display: none;" class="tab-pane" >
                          @{
                              if (RecommendedList.Count() != 0)
                              {
                             <span class="label label-info">Number of publications: @RecommendedList.Count()</span>
				             <a class="pull-right">@Html.DropDownList("Category", new SelectList(@Fields))</a>
                  <table class="span7">  
                   
                @foreach (var item in RecommendedList)
                {
                    string mouseid1 = "#mouse" + @item.publicationID;
                    string mouseid2 = "mouse" + @item.publicationID;
                
                    <tr><td>
                    
                <div style="border-bottom: 1px solid grey; margin: 10px 0px;">
                <div style="float: left;" id="mouse" class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="@mouseid1" >
                    @if (item.imagename != "" && item.imagename != null)
                    {
                            <img class="mouseover" src="../../Content/Files/@item.UserProfile.UserName/Publications/@item.imagename" alt="" style="margin-left: auto; margin-right: auto;width: 50px;"/>
                    }
                    else
                    {
                            <img src="../../Content/images/Pub1.png" alt="" style="margin-left: auto; margin-right: auto;width: 50px;"/>
                    }
                </div>
                <div style="margin-left: 8px; float: left;">
                    <a href="/PublicationModel/Details/@item.publicationID" id="title"><b>@item.title</b></a> 
                    <div id="Author">Author(s) : @item.author</div>
                    <div id="Year">Year of Publication : @item.year</div>
                    <div id="@mouseid2" class="accordion-body collapse" >
                    @{if (@item.keyword != null)
                      {<div id="keyword">Keyword(s) : @item.keyword</div>}}
                    @{if (@item.journal != null)
                      {<div id="journal">Journal : @item.journal</div>}}
                    @{if (@item.conference != null)
                      {<div id="conference">Conference : @item.conference</div>}}
                    @{if (@item.university != null)
                      {<div id="university">University : @item.university</div>}}
                </div>
                </div>
                <div style="float: right; margin-right: 5px; color: #888; font-size: 15px;">@Html.DisplayFor(modelItem => item.type)
                    | @Html.DisplayFor(modelItem => item.status)  |
                    <div style="float:right; font-size: 15px; margin-left: 5px;">
                        @Html.ActionLink("More>>", "Details", new { id = item.publicationID })
                    </div>
                    </div>
            </div>
            <hr /> 
            </td></tr>
   
                }
                </table>
                              }
                              else
                              {
                <span class="label label-info">Number of recommended publications: @RecommendedList.Count()</span>
                              }
      }  
                    </div>
                    <div id="tab2" style="display: none;" class="tab-pane" >
                      
        @{
            
                <span class="label label-info">Number of publications uploaded: @UploadedPub.Count()</span>
                <a class="btn btn-primary pull-right" href="@Url.Content("~/PublicationModel/Create/1")">
                <i class="icon-upload icon-white"></i>Add new</a> 
            if (UploadedPub.Count() != 0)
            {               
                <table class="span7">    
                @foreach (var item in UploadedPub)
                {
                    <tr><td>
               
                <div style="border-bottom: 1px solid grey; margin: 10px 0px;">
                <div style="float: left;" id="Image" class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#@item.publicationID">
                   @if (item.imagename != "" && item.imagename != null)
                   {
                            <img class="mouseover" src="../../Content/Files/@item.UserProfile.UserName/Publications/@item.imagename" alt="" style="margin-left: auto; margin-right: auto;width: 50px;"/>
                   }
                   else
                   {
                            <img src="../../Content/images/Pub1.png" alt="" style="margin-left: auto; margin-right: auto;width: 50px;"/>
                   }
                        
                </div>
                <div style="margin-left: 8px; float: left;">
                    <a href="/PublicationModel/Details/@item.publicationID" id="title"><b>@item.title</b></a> 
                    <div id="Author">Author(s) : @item.author</div>
                    <div id="Year">Year of Publication : @item.year</div>
                    <div id="@item.publicationID" class="accordion-body collapse" >
                    @{if (@item.keyword != null)
                      {<div class="hidden" id="Keyword">Keyword(s) : @item.keyword</div>}}
                    @{if (@item.journal != null)
                      {<div class="hidden" id="Journal">Journal : @item.journal</div>}}
                    @{if (@item.conference != null)
                      {<div class="hidden" id="Conference">Conference : @item.conference</div>}}
                    @{if (@item.university != null)
                      {<div class="hidden" id="University">University : @item.university</div>}}
                      </div>
                </div>
                <div style="float: right; margin-right: 5px; color: #888; font-size: 15px;">@Html.DisplayFor(modelItem => item.type)
                    | @Html.DisplayFor(modelItem => item.status)  |
                    <div style="float:right; font-size: 15px; margin-left: 5px;">
                        @Html.ActionLink("More>>", "Details", new { id = item.publicationID })
                    </div>
                    </div>
            </div>
            <hr /> 
            </td></tr>
                }
                </table>
            }
      }  
      </div>
               </div>
            </div>  
            <div class="span4" style="position:relative">
					<div class="pull-left">
					<h5>Recent Publications</h5>
							<!--<div class=""><div class="hero-unit"></div></div>-->
							<div class="accordion" id="accordion2">
                            @{
                              int number = 1;
                              string hrefid1 = "#collapse" + 1;
                              string hrefid2 = "collapse" + 1;
                              if (@myprofile.Specializations.Count() > 0)
                              {
                                  foreach (var row in @myprofile.Specializations)
                                  {
                                      hrefid1 = "#collapse" + number;
                                      hrefid2 = "collapse" + number;
                                  <div class="accordion-group">
						          <div class="accordion-heading">
						            <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="@hrefid1">
						              @row.Field
						            </a>
						          </div>
						          <div id="@hrefid2" class="accordion-body collapse">
						            <div class="accordion-inner">
                                     @{foreach (var row2 in db.Query("Select * from PublicationModels where specialisation='" + @row.Field + "' ORDER BY timestamp DESC"))
                                       {
                                        <li><a href="/PublicationModel/Details/@row2.publicationID">@row2.Title</a></li>
                                       }
                                       }
						              <a class="pull-right" href="@Url.Content("~/Forum/CategoryDetail/?Category=" + @row.Field)" style="font-size:10px">View All</a>
						            </div>
						          </div>
						        </div>
                                       number++;
                                  }
                              }     
                            }
						    </div>
                        </div>
                </div>
</div>


@Html.Partial("_Footer")
@helper Script(string scriptName)
    {
    <script src="@Url.Content("~/Scripts/" + scriptName)" type="text/javascript"></script>
}
 	    
<script type="text/javascript" language="javascript">
    $('.hidden').hide(function () {
        $('#Keyword').hide();
        $('#Journal').hide();
        $('#Conference').hide();
        $('#University').hide();
    });

    $(document).ready(function () {
        tab('tab1');
    });


    $('.carousel').carousel({
        interval: 2000
    });

    $('#myModal').modal()
    $('#myModal').modal('hide')

    $('.mouseover').mouseover(function () {
        id = id.toString();
        $('#Keyword' + id).slideDown("fast");
        $('#Journal' + id).slideDown("fast");
        $('#Conference' + id).slideDown("fast");
        $('#University' + id).slideDown("fast");
        alert(id);
    });
    $('.mouseover').mouseout(function () {
        var id = $("#mouse").val();
        $('#Keyword' + id).hide();
        $('#Journal' + id).hide();
        $('#Conference' + id).hide();
        $('#University' + id).hide();
    });

    function tab(tab) {
        document.getElementById('tab1').style.display = 'none';
        document.getElementById('tab3').style.display = 'none';
        document.getElementById('tab4').style.display = 'none';
        document.getElementById('tab2').style.display = 'none';
        document.getElementById('li_tab1').setAttribute("class", "");
        document.getElementById('li_tab3').setAttribute("class", "");
        document.getElementById('li_tab4').setAttribute("class", "");
        document.getElementById('li_tab2').setAttribute("class", "");
        document.getElementById(tab).style.display = 'block';
        document.getElementById('li_' + tab).setAttribute("class", "active");
    }

</script>